package com.ihr360.payroll.service.salarytasklet.convertor;

import com.ihr360.attendance.AttendancePeriodReport;
import com.ihr360.common.DateRange;
import com.ihr360.commons.model.IConvertor;
import com.ihr360.payroll.model.dto.attendance.report.AttendanceMonthlyReport;
import com.ihr360.payroll.model.dto.attendance.report.embeddable.AttendanceReportFixedPart;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
/**
 * @author davidwei
 */
@Component
public class MonthlyReportToPeriodReportConvertor implements IConvertor<AttendancePeriodReport, AttendanceMonthlyReport> {
    @Override
    public AttendancePeriodReport convertDtoToEntity(AttendanceMonthlyReport entity) {
        if (entity == null) {
            return null;
        }
        AttendancePeriodReport target = new AttendancePeriodReport();
        BeanUtils.copyProperties(entity, target);
        target.setDateRange(DateRange.build(entity.getStartDate(), entity.getEndDate()));
        AttendanceReportFixedPart fixedPart = entity.getFixedPart();
        com.ihr360.attendance.AttendanceReportFixedPart targetPart = new com.ihr360.attendance.AttendanceReportFixedPart();
        BeanUtils.copyProperties(fixedPart, targetPart);
        target.setFixedPart(targetPart);
        if (entity.getFlexPart() != null) {
            target.setFlexPart(entity.getFlexPart().getItems());
        }
        return target;
    }

    @Override
    public AttendanceMonthlyReport convertEntityToDto(AttendancePeriodReport dto) {
        AttendanceMonthlyReport target = new AttendanceMonthlyReport();
        BeanUtils.copyProperties(dto, target);
        return target;
    }
}